﻿using Crowler.Dispatcher.DataContract;
using Crowler.Model.CoreComponents;
using Crowler.Model.Dispetcher.BusinessComponents;
using Crowler.Model.Dispetcher.DataAccess;

namespace Crowler.Dispatcher.BusinessService
{
    public class GetNewEntryToDiscoverService : BusinessServiceBase<IVoidRequest, FetchUndescoveredEntryServiceResponse>
    {
        private readonly IDiscoverableEntryBc _discoverableEntryBc;
        private readonly IDiscoverableEntryRepository _discoverableEntryRepository;


        public GetNewEntryToDiscoverService(IDiscoverableEntryBc discoverableEntryBc, IDiscoverableEntryRepository discoverableEntryRepository)
        {
            _discoverableEntryBc = discoverableEntryBc;
            _discoverableEntryRepository = discoverableEntryRepository;
            Response = new FetchUndescoveredEntryServiceResponse();
        }

        public override void Execute()
        {
            var workingDomains = _discoverableEntryRepository.GetWorkingSetDomains();
            var result = _discoverableEntryBc.GetEntryToDiscover(workingDomains);

            ServiceResponse.Url = result.EntryUrl;
        }

        public override void InitializeDefaultResponse()
        {
            Response = new FetchUndescoveredEntryServiceResponse();
        }

    }
}
